package com.hanlp.common;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;

/**
 * http工具类
 */
public class HttpUtils {
    public String doGet(String url){
        CloseableHttpClient client = HttpClients.custom().build();
        CloseableHttpResponse response = null;
        try {
            response = client.execute(new HttpGet(url));
            HttpEntity entity = response.getEntity();
            return entity.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }


    public String doGet(String url,String param){
        CloseableHttpClient client = HttpClients.custom().build();
        CloseableHttpResponse response = null;
        try {
            response = client.execute(new HttpGet(url));
            HttpEntity entity = response.getEntity();
            return entity.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }


}
